<template>
  <div id="app">
    <div class="content">
      <navigation>
        <router-view v-if="isReady"></router-view>
      </navigation>
    </div>
  </div>
</template>
<script>
import ApplicationDao from '@/daos/application';

export default {
  components: {},
  name: 'App',
  data() {
    return {
      isReady: true,
      informTag: false,
    };
  },
  provide() {
    return {
      backToHomepage: this.backToHomepage,
      backToG6page: this.backToG6page,
      getTimes: this.getTimes,
    };
  },
  watch: {
    $route() {
      // 通知设置已读
      let { informId } = this.$route.query;
      if (informId && !this.informTag) {
        this.informTag = true;
        this.handleNoticeRead(informId);
      }
      //   this.$nextTick(()=>{
      //  const el =   document.querySelector('.content')
      //  this.$tv.requestFocus(el)
      // })
    },
  },
  created() {
    let user = JSON.parse(localStorage.getItem('user'));
    if (user && (user.orgId || user.roleAction)) {
      localStorage.removeItem('user');
      localStorage.removeItem('filterCache');
      this.$commom.alert('请重新登录');
      this.backToHomepage();
    }
    if (JSON.parse(this.getQueryVariable('ssoToken') ? this.getQueryVariable('ssoToken') : 'false')) {
      localStorage.setItem('ssoDomain', decodeURIComponent(this.getQueryVariable('ssoDomain')));
      this.isReady = false;
      this.$http(this.$API.getUserInfo, {}).then((res) => {
        if (res) {
          this.$store.commit('saveUser', res);
          this.isReady = true;
        }
      });
    }
    this.getLeftMenu();
  },
  methods: {
    // 返回首页公共方法
    backToHomepage() {
      let domain = localStorage.getItem('ssoDomain'),
        data = this.getTimes();
      if (domain) {
        window.location.href = domain + '?time=' + data;
      } else {
        this.$router.push({ name: 'homepage', query: { time: data } });
      }
    },
    // 返回G6公共方法
    backToG6page(tag = 'g6') {
      let data = this.$store.state.application;
      let menu = this.$store.state.appMenuList;
      let { meta, name } = this.$route;
      let result = menu.find((e) => e.name === meta.title);
      let g6menu = (localStorage.getItem('g6menu') || '').split(',');
      if (tag === 'g6') {
        if (result) {
          this.$store.commit('setApplication', {
            pageId: name,
            moduleId: result.id,
            pageName: result.name,
          });
        }
        let index = g6menu.indexOf(name);
        if (index > -1) {
          g6menu.splice(index, 1);
        }
        localStorage.setItem('g6menu', g6menu.join(','));
        this.$router.push({ name: 'g6issue' });
      } else {
        let index = g6menu.indexOf(data.pageId);
        if (index === -1) {
          g6menu.push(data.pageId);
        }
        localStorage.setItem('g6menu', g6menu.join(','));
        this.$router.replace(
          { path: `/${data.pageId}` },
          () => {},
          () => {}
        );
      }
    },

    // 获取时间戳
    getTimes() {
      let date = new Date().getTime().toString();
      return date;
    },
    getLeftMenu() {
      if (this.$store.state.appMenuList.length) {
        return;
      }
      ApplicationDao.getLeftMenu({ moduleType: 1 }, (res) => {
        if (res.data) {
          this.$store.commit('setAppMenu', res.data || []);
        }
      });
    },
    handleNoticeRead(id) {
      let params = {
        id,
        showState: 1,
      };
      ApplicationDao.patchInformRecordStatus(params);
    },
    getQueryVariable(variable) {
      var query = window.location.href.split('?')[1];
      if (query) {
        var vars = query.split('&');
        for (var i = 0; i < vars.length; i++) {
          var pair = vars[i].split('=');
          if (pair[0] == variable) {
            return pair[1];
          }
        }
        return false;
      }
    },
  },
};
</script>

<style lang="less">
body {
  padding: 0;
  margin: 0;
}
* {
  -webkit-overflow-scrolling: touch;
}
p {
  margin: 0;
}
input {
  border: none;
  padding: 0;
  background: none;
}
textarea {
  resize: none;
}
input:focus,
textarea:focus {
  outline: none;
}
input::-webkit-input-placeholder,
textarea::-webkit-input-placeholder {
  color: #495889;
} /* 使用webkit内核的浏览器 */
input:-moz-placeholder,
textarea:-moz-placeholder {
  color: #495889;
} /* Firefox版本4-18 */
input::-moz-placeholder,
textarea:-moz-placeholder {
  color: #495889;
} /* Firefox版本19+ */
input:-ms-input-placeholder,
textarea:-moz-placeholder {
  color: #495889;
} /* IE浏览器 */
a {
  text-decoration: none;
}
ul {
  padding-left: 0;
  margin: 0;
  list-style: none;
}
img {
  width: 100%;
  height: 100%;
}
#app,
.content {
  height: 100%;
}
.content .vux-slider > .vux-indicator > a > .vux-icon-dot.active,
.content .vux-slider .vux-indicator-right > a > .vux-icon-dot.active {
  background: #ffffff;
}
.weui-toast {
  width: 120px;
}
.weui-toast_forbidden {
  width: 150px !important;
}
.weui-toast.vux-toast-bottom {
  left: 50%;
  bottom: 30% !important;
  transform: translate(-50%, 0);
  background: rgba(255, 255, 255, 0.8);
  color: #333333;
  font-size: 15px;
  border-radius: 50px;
  transition: unset;
}
.weui-toast.vux-toast-bottom.weui-toast_text .weui-toast__content {
  padding: 10px 20px !important;
  white-space: nowrap;
}
.filter_page_confirm {
  .weui-dialog {
    background: #e8e9ed;
  }
  .weui-dialog__bd {
    padding-bottom: 40px;
  }
  .weui-dialog__ft {
    line-height: 32px; /* no */
    font-size: 15px;
    &::after {
      border-color: rgba(69, 109, 230, 1);
    }
    .weui-dialog__btn {
      &::after {
        border-color: rgba(69, 109, 230, 1);
      }
    }
    .weui-dialog__btn_default {
      color: #456de6;
      &::before {
        content: ' ';
        position: absolute;
        left: 0;
        top: 0;
        width: 1px;
        bottom: 0;
        border-left: 0.026667rem solid rgba(69, 109, 230, 1);
        color: rgba(69, 109, 230, 1);
        -webkit-transform-origin: 0 0;
        transform-origin: 0 0;
        -webkit-transform: scaleX(0.5);
        transform: scaleX(0.5);
      }
      &::after {
        content: '';
        position: absolute;
        left: 0;
        width: 1px;
        bottom: 0;
        border-bottom: 0.026667rem solid rgba(69, 109, 230, 1);
        color: rgba(69, 109, 230, 1);
        -webkit-transform-origin: 0 0;
        transform-origin: 0 0;
        -webkit-transform: scaleX(0.5);
        transform: scaleX(0.5);
      }
    }
    .weui-dialog__btn_primary {
      background: #456de6;
      color: #fff;
    }
  }
}
.myScrollUpRefreshWarp {
  min-height: 30px;
  padding: 15px 0;
  text-align: center;
  visibility: hidden;
  .upRefreshProgress {
    display: inline-block;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 1px solid #456de6;
    border-bottom-color: #eaeaea;
    vertical-align: middle;
  }
  .refresh-tip {
    display: inline-block;
    font-size: 12px;
    color: rgba(255, 255, 255, 1);
    vertical-align: middle;
    margin-left: 6px;
  }
  .refreshRotate {
    -webkit-animation: mescrollRotate 0.6s linear infinite;
    animation: mescrollRotate 0.6s linear infinite;
  }
}
.my-downwarp,
.my-downwarp-normal {
  position: relative;
  width: 100%;
  height: 0;
  text-align: center;
  overflow: hidden;
  .total_num_view {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translate(-50%, 0);
    height: 44px; /* no */
    line-height: 45px; /* no */
    text-align: center;
    font-size: 14px;
    color: #333333;
    width: 164px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50px;
  }
  .downwarp-content {
    position: absolute;
    left: 0;
    bottom: 0;
    padding-top: 1px;
    width: 100%;
    height: 60px;
    .downwarp-progress {
      display: block;
      margin: 0 auto;
      width: 32px;
      height: 32px;
      border-radius: 50%;
      border: 1px solid #456de6;
      border-bottom-color: #eaeaea;
    }
    .downwarp-tip {
      margin-top: 3px;
      font-size: 12px;
      color: rgba(255, 255, 255, 0.6);
      vertical-align: middle;
    }
    .mescroll-rotate {
      -webkit-animation: mescrollRotate 0.6s linear infinite;
      animation: mescrollRotate 0.6s linear infinite;
    }
  }
}
.my-downwarp-normal {
  .downwarp-content {
    top: 10px;
  }
}
.myUpwarpNodata {
  font-size: 12px;
  color: #fff;
  line-height: 22px;
}

@-webkit-keyframes mescrollRotate {
  0% {
    -webkit-transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
  }
}

@keyframes mescrollRotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
</style>
